<template>
  <el-dialog :title="`${isEdit ? '编辑' : '新增'}车辆`" :visible.sync="dialogVisible" width="30%" :close-on-click-modal="false" :before-close="close">
    <div>
      <el-form ref="RefForm" :model="formData" label-width="100px" :validate-on-rule-change="false" :rules="formRules" status-icon>
        <el-form-item label="RFID卡" prop="rfid">
          <el-input v-model="formData.rfid" maxlength="20" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="车辆类型" prop="carType">
          <el-input v-model="formData.carType" maxlength="20" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="车牌号" prop="plateNumber">
          <el-input v-model="formData.plateNumber" maxlength="13" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="负责人" prop="responsibleMan">
          <el-input v-model="formData.responsibleMan" maxlength="20" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="负责人电话" prop="responsiblePhone">
          <el-input v-model="formData.responsiblePhone" maxlength="13" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="formData.remark" maxlength="200" show-word-limit type="textarea"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button :loading="loadingSubmit" type="primary" @click="handleSubmit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import dialogEditMixin from "@/mixins/dialogEdit"
  import { eleValidator } from "@/utils/tools"
  export default {
    mixins: [dialogEditMixin],
    data() {
      return {
        options: [],
        optionsName: [
          { label: "施工队员", value: "施工队员" },
          { label: "施工队长", value: "施工队长" },
          { label: "科室人员", value: "科室人员" },
        ],
        formRules: {
          rfid: [
            {
              validator: eleValidator([
                { rule: 'isRepeat', msg: { value: '车辆RFID与人员RFID中不可有重复', url: '/Car/Exists', key: 'rfid' } }
              ]),
              trigger: "blur",
            },
          ],
          carType: [
            { required: true, message: "请输入车辆类型", trigger: "blur" },
            {
              validator: eleValidator([
                { rule: "isEmpty", msg: "车辆类型不能为空" },
              ]),
              trigger: "blur",
            },
          ],
          plateNumber: [
            { required: true, message: "请输入车牌号", trigger: "blur" },
            {
              validator: eleValidator([
                { rule: "isEmpty", msg: "车牌号不能为空" },
                { rule: 'isRepeat', msg: { value: '车牌号重复', url: '/Car/Exists', key: 'plateNumber' } }
              ]),
              trigger: "blur",
            },
          ]
        }
      }
    },
    methods: {
      resetFormData() {
        this.formData = {
          rfid: "",
          carType: "",
          plateNumber: "",
          responsibleMan: "",
          responsiblePhone: "",
          remark: "",
        }
      },
    },
  }
</script>

<style lang="scss" scoped></style>
